<?php
/**
 * Created by PhpStorm.
 * User: Jerry
 * Date: 2017/1/5
 * Time: 16:52
 */

namespace YMApi\Model;
use Think\Model;

/**
 * Class BuyNowNoticeModel
 * @package SDXApi\Model
 */
class BuyNowNoticeModel extends Model
{
	/**
	 * @var string
	 */
	protected $tableName = 'buy_now_notice';

	/**
	 * 添加订阅通知
	 * Created by Jerry
	 * @param $data
	 * @return mixed
	 */
	public function store($data) {
		if ($this->create($data)) {
			return $this->add();
		}

		throw_exception($this->getError());
	}

	/**
	 * 索取所有为发送短信的秒杀订阅
	 * Created by Jerry
	 * @return mixed
	 */
	public function findBuyNowNoticeList()
	{
		$where = array(
			'status' =>	0,
		);
		return $this->where($where)->select();
	}

	/**
	 * 设置发送状态
	 * Created by Jerry
	 * @param $id
	 * @return bool
	 */
	public function updateBuyNowNoticeStatus($id)
	{
		$where = array(
			'id'	=>	$id,
		);

		return $this->where($where)->setField('status', 1);
	}

	/**
	 * 判断是否已订阅通知
	 * Created by Jerry
	 * @param $user_id
	 * @param $goods_id
	 * @return mixed
	 */
	public function isNotice($user_id, $goods_id)
	{
		$where = array(
			'user_id'	=>	$user_id,
			'goods_id'	=>	$goods_id,
		);

		return $this->where($where)->count();
	}
}